package ice;


import com.guo.util.ResourceUtil;
import com.slice2java.HelloPrx;
import com.zeroc.Ice.Application;
import com.zeroc.Ice.LocalException;

public class Client2 extends Application {

    @Override
    public int run(String[] args) {
        if (args.length > 0) {
            System.err.println(appName() + ": too many arguments");
            return 1;
        }
        System.out.println("创建客户端代理...");
        HelloPrx helloPrx = HelloPrx.checkedCast(communicator().propertyToProxy("Hello.Proxy")).ice_twoway().ice_secure(false);
        if (helloPrx == null) {
            System.err.println("invalid proxy");
            return 1;
        }
        int i = 0;
        // 调用Server 模拟通信
        System.out.println("准备发送数据...");
        while (i >= 0) {
            i++;
            System.out.println("发送数据：" + i);
            helloPrx.sayHello("hello-" + i);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        String clientConfigPath = ResourceUtil.getResourcePath("/ice/config.client");
        Client2 app = new Client2();
        int status = app.main("Client", args, clientConfigPath);
        System.exit(status);
    }
}
